<?php

namespace App\Http\Controllers;

use App\Exports\Scan\FlightExport;
use App\Http\Resources\BaseCollection;
use App\Repositories\Contracts\ScanInterface;
use Curl\CurlService\CurlService;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class ScanController
{
    private $scanInterface;
    public function __construct(ScanInterface $scanInterface)
    {

    }

    /**
     * 数据列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function lists(){
        return view('scan.lists');
    }

    /**
     * 数据列表
     * @param Request $request
     * @return mixed
     */
    public function ajaxLists(Request $request){

        $param = [];
        if ($request->task_id) {

            $param['task_id'] = $request->task_id;
        }
        if ($request->airline) {
            $param['hs_code'] = $request->airline;
        }
        if ($request->depart_code) {
            $param['depart_city_code'] = $request->depart_city_code;
        }

        if ($request->arrived_code) {
            $param['arrived_city_code'] = $request->arrived_city_code;
        }

        $param['page']          = $request->page;
        $param['page_size']     = $request->page_size;

        $res = CurlService::get(env('CRM_URL').'/flight/ajaxLists?'.http_build_query($param));
        return $res;
    }

    /**
     * 下载地址
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
     */
    public function download(Request $request) {

        return Excel::download(new FlightExport(),'数据下载'.date('YmdHis').'.xlsx');
    }
}